feat(rm): offer to delete the branch after removing a worktree - #13
Conversation
2e15865 to
b5009dd
Compare
There was a problem hiding this comment.
🟡 Changes recommended
There is a confirmed detached-worktree branch resolution bug in _wt_branch_of (and related state handling) and a mismatch where wt merged --rm can fail the command on branch delete failures despite the documented “non-fatal” behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds optional branch cleanup to worktree removal flows so that wt rm and wt merged --rm can offer (or perform unattended) deletion of the branches associated with removed worktrees, using safe git branch -d semantics.
Changes:
- Introduces branch lookup/deletion helpers and integrates branch cleanup into
wt rmandwt merged --rm(with new--rm-branch/--keep-branchflags). - Updates help/README to document the new flags and behavior.
- Adds Bats tests covering interactive and unattended branch cleanup scenarios for both commands.
File summaries
| File | Description |
|---|---|
lib/core.sh |
Adds helpers to find a worktree’s checked-out branch and delete branches safely. |
lib/commands/rm.sh |
Adds --rm-branch / --keep-branch and branch cleanup prompt/logic after worktree removal. |
lib/commands/merged.sh |
Adds --rm-branch and batch branch cleanup after wt merged --rm removals. |
lib/commands/help.sh |
Documents new CLI flags for rm and merged. |
README.md |
Documents branch cleanup behavior and new flags. |
test/rm.bats |
Adds tests for wt rm branch cleanup behaviors. |
test/merged.bats |
Adds tests for wt merged --rm batch branch cleanup behaviors. |
Review details
Suppressed comments (1)
lib/commands/merged.sh:117
_wt_merged_rm_branchescurrently returns non-zero if anygit branch -dfails, which makeswt merged --rmfail the whole command. The PR description/README state branch deletion failures should be reported but not fail the command (matching_wt_rm_branch_cleanup, which ignores delete failures).
_wt_del_branch "$b" || rc=1
done <<< "$removed"
return "$rc"
}
- Files reviewed: 7/7 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
`wt rm` and `wt merged --rm` left the branch behind, which piles up fast with Claude Code's worktree-* branches. Both now offer to clean them up: `wt rm` asks about its one branch, `wt merged --rm` asks once for the whole batch (and only for worktrees it actually removed). `-y` answers yes to every prompt, so `wt merged --rm -y` now deletes the merged branches too. Deletion always goes through `git branch -d`, never --force, so an unmerged branch is refused and reported without failing the command. With nothing on stdin to answer with, the prompt goes unanswered and the branch is kept, leaving non-interactive callers unaffected. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Matches wt rm, where git's own error is reported but not fatal. Also corrects the README's name for git's forced delete flag (-D). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
b5009dd to
e312831
Compare
|
Addressed the review in e312831:
Rebased onto |
Removing a worktree left its branch behind.
wt rmnow asks about its one branch, andwt merged --rmasks once for the whole batch (only for worktrees it actually removed).-yanswers yes to every prompt, sowt merged --rm -ynow deletes the merged branches too — the one behaviour change for existing scripts. Deletion always usesgit branch -d, never--force, so an unmerged branch is refused and reported without failing the command, and the branches it does delete are merged into the base already. With nothing on stdin to answer with the prompt goes unanswered and the branch is kept, so non-interactive callers are otherwise unaffected.Stacked on #12; retarget to
mainonce that merges.🤖 Generated with Claude Code